<include file="public@header"/>

<link href="__TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" media="all" rel="stylesheet">
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li  class="active"><a href="{:url('Discount/index')}">优惠活动管理</a></li>
        <li>
            <a href="#" id="new_card" >新建</a>
        </li>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('Discount/index')}">
        <label class="col-lg-5 col-md-6 col-xs-12 form-group" >
            日期:
            <input type="text" class="form-control" name="start_time" id="start_stime_so"
                   value="{$param.start_time|default=''}" placeholder="">-
            <input type="text" class="form-control" name="end_time" id="end_stime_so"
                   value="{$param.end_stime|default=''}" placeholder="">
        </label>
        <label class="col-md-3 col-sm-6  form-group">
            类型:
            <select class="form-control" name="type" id="is_used">
                <option value="0">全部</option>
                <if condition="isset($param.type) && $param.type==1">
                    <option value="1" selected>满减</option>
                    <else/>
                    <option value="1">满减</option>
                </if>
                <if condition="isset($param.type) && $param.type==2">
                    <option value="2" selected>打折</option>
                    <else/>
                    <option value="2">打折</option>
                </if>
            </select>
        </label>
        <label class="col-md-3 col-sm-6   form-group">
            <input type="submit"  class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('Discount/index')}">清空</a>
        </label>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('Discount/delete')}" data-subcheck="true" data-msg="您确定删除吗？">
                批量删除
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th width="50">编号</th>
                <th width="100">类型</th>
                <th width="100">金额</th>
                <th width="100">减去金额</th>
                <th width="100">打折</th>

                <th width="70">发放日期</th>
                <th width="70">有效期</th>
                <th width="150">操作</th>
            </tr>
            </thead>
            <foreach name="data" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>{$vo.id}</td>

                    <td>
                        <if condition="!empty($vo.type) && $vo.type==1">
                            满减
                            <else />
                            打折
                        </if>
                    </td>
                    <td>{$vo.total_price}（元)</td>
                    <td>
                        <if condition="!empty($vo.type) && $vo.type==1">
                           {$vo.reduce_price}(元)
                            <else />
                            打折活动
                        </if>
                    <td>
                        <if condition="!empty($vo.type) && $vo.type==2">
                            {$vo.discount}
                            <else />
                            满减活动
                        </if>
                    </td>

                    <td>
                        {:date('Y-m-d ',$vo.start_time)}
                    </td>
                    <td>
                            {:date('Y-m-d ',$vo.end_time)}
                        </if>
                    </td>
                    <td>
                        <a href="{:url('Discount/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                    </td>
                </tr>
            </foreach>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>
<div id="card_add_msg"  style="display: none">
    <form action="{:url('Discount/addPost')}" method="post" class="well row js-ajax-form " style="margin:0px;">
        <label class="form-group" for="" id="type">
            类型:<span class="form-required">*</span>
            <select name="type" id="">
                <option value="0">请选择类型</option>
                <option value="1">满减</option>
                <option value="2">打折</option>
            </select>
        </label>
        <br/>
        <label class="form-group" for="" id="total_price">
            满金额:<span class="form-required">*</span>
            <input class="form-control" type="number" name="total_price" required="required" placeholder="请输入金额">
        </label>
        <label class="form-group" for="" id="reduce_price">
            减金额:<span class="form-required">*</span>
            <input class="form-control" type="number" name="reduce_price" required="required" placeholder="请输入金额">
        </label>
        <label class="form-group" for="" id="discount">
            打折:<span class="form-required">*</span>
            <input class="form-control" type="number" name="discount" required="required" placeholder="请输入打几折">
        </label>
        <label class="form-group" for="">
            有效时间:<span class="form-required">*</span>
            <input class="form-control" type="text" name="start_time"  id='start_time' required="required" placeholder="请输入开始时间">
        </label>
        <label class="form-group" for="">
            结束时间:<span class="form-required">*</span>
            <input class="form-control" type="text" name="end_time" id='end_time' required="required" placeholder="请输入结束时间">
        </label>
        <input type="submit" id="submit" style="display:none;" class="btn btn-primary js-ajax-submit ">
    </form>
</div>


<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<script>
    $(function()
    {
        $('#start_time').datepicker();
        $('#end_time').datepicker();
        $('#end_stime_so').datepicker();
        $('#start_stime_so').datepicker();

        $("body").on("click",'#new_card',function()
            {
                var $type=$("[name='type']").val();
                var $card=$("[name='card']").val();
                var $amount=$("[name='amount']").val();
                var $student_id=$("[name='student_id']").val();
                var valid_date=$("[name='valid_date']").val();
                $('input').blur(function ()
                {
                    $type=$("[name='$type']").tnameval();
                    $card=$("[name='card']").val();
                    $amount=$("[name='amount']").val();
                    $student_id=$("[name='student_id']").val();
                })
                layer.open
                ({
                    type: 1,
                    btn: ['提交'],
                    title: '添加优惠活动',
                    content: $('#card_add_msg'),
                    yes: function (index,layero)
                    {
                        $('#submit').click();
                    }
                   })
             })
        $('body').on('change','#type',function()
        {
            $type=$(this).find("option:selected").val();
            if($type==1)
            {
                if($("#reduce_price").is(":hidden"))
                {
                    $("#reduce_price").show();

                }

                if($("#discount").is(":visible"))
                {
                    $("#discount").hide();
                }
            }
            else if($type==2)
            {

                if($("#reduce_price").is(":visible"))
                {
                    $("#reduce_price").hide();
                }
                if($("#discount").is(":hidden"))
                {
                    $("#discount").show();
                }
            }

        })
    })
</script>
</body>
